#
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import re
from pkg_resources import resource_filename

from trac.core import *
from trac.util import escape
from trac.wiki import IWikiSyntaxProvider


class LaTeXSupport(Component):
	"""Provides support for LaTeX in Trac's wiki."""

	implements(ITemplateProvider, IWikiSyntaxProvider)

	# IWikiSyntaxProvider methods

	def get_wiki_syntax(self):
		"""Replace textual patterns representing LaTeX text with escaped text"""

		def _replace(formatter, namespace, match):
			src = self.env.href.chrome('emoticons', EMOTICONS[match.group(0)])
			return '<img src="%s" alt="%s" class="emoticon" width="18" ' \
				   'height="18" style="vertical-align: middle" />' % (
				   escape(src), escape(match.group(0)))
		pattern = '|'.join([re.escape(pattern) for pattern in { ':)' : ':-----)' }])
		yield '\b' + pattern + '\b', _replace

	# ????
	def get_link_resolvers(self):
		return []

